//
//  MeViewController.swift
//  willdo
//
//  Created by zz on 3/14/18.
//  Copyright © 2018 will do. All rights reserved.
//

import UIKit

class MeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                self.edgesForExtendedLayout = UIRectEdge(rawValue: 0)
        setupView()
    }

    let infoView = UIView()
    let imgView = UIImageView()
    let nameLabel = UILabel()
    let posLabel = UILabel()
    
    let telImg = UIImageView()
    let telLabel = UILabel()
    let emailImg = UIImageView()
    let emailLabel = UILabel()
    let belongImg = UIImageView()
    let belongLabel = UILabel()
    let posImg = UIImageView()
    let positionLabel = UILabel()
    let noteImg = UIImageView()
    let noteLabel = UILabel()
    let noticeImg = UIImageView()
    let noticeLabel = UILabel()
    
    private func setupView(){
        view.addSubview(infoView)
        infoView.backgroundColor = UIColor(hexString:"f9f9fb")
        infoView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(101)
        }
        infoView.addSubview(imgView)
        imgView.image = UIImage(named:"head portrait")
        imgView.layer.cornerRadius = 50
        imgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(24)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(55)
        }
        infoView.addSubview(nameLabel)
        nameLabel.text = "张三"
        nameLabel.font = UIFont.init(name: "PingFang SC", size: 18)
        nameLabel.textColor = UIColor(hexString: "#496069")
        nameLabel.sizeToFit()
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(imgView)
            make.left.equalTo(imgView.snp.right).offset(23)
        }
        infoView.addSubview(posLabel)
        posLabel.text = "组织部部长"
        posLabel.textColor = UIColor(hexString: "#496069")
        posLabel.font = UIFont.init(name: "PingFang SC", size: 12)
        posLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel)
            make.bottom.equalTo(imgView)
        }
        
        let telView = getCell(img: telImg, label: telLabel)
        telImg.image = UIImage(named:"contact_picture")
        telLabel.text = "18100000000"
        telView.snp.makeConstraints { (make) in
            make.top.equalTo(infoView.snp.bottom).offset(11)
            make.left.right.equalToSuperview()
            make.height.equalTo(52)
        }
        let emailView = getCell(img: emailImg, label: emailLabel)
        emailImg.image = UIImage(named:"email_picture")
        emailLabel.text = "18100000000@qq.com"
        emailView.snp.makeConstraints { (make) in
            make.top.equalTo(telView.snp.bottom)
            make.left.right.height.equalTo(telView)
        }
        let belongView = getCell(img: belongImg, label: belongLabel)
        belongImg.image = UIImage(named:"department_picture")
        belongLabel.text = "部长"
        belongView.snp.makeConstraints { (make) in
            make.top.equalTo(emailView.snp.bottom)
            make.left.right.height.equalTo(emailView)
        }
        let posView = getCell(img: posImg, label: positionLabel)
        posImg.image = UIImage(named:"work_picture")
        positionLabel.text = "组织部部长"
        posView.snp.makeConstraints { (make) in
            make.top.equalTo(belongView.snp.bottom)
            make.left.right.height.equalTo(belongView)
        }
        let noteView = getCell(img: noteImg, label: noteLabel)
        noteImg.image = UIImage(named:"remark_picture")
        noteLabel.text = "备注"
        noteView.snp.makeConstraints { (make) in
            make.top.equalTo(posView.snp.bottom)
            make.left.right.height.equalTo(posView)
        }
        let noticeView = getCell(img: noticeImg, label: noticeLabel)
        noticeImg.image = UIImage(named:"inform_picture")
        noticeLabel.text = "通知"
        noticeView.snp.makeConstraints { (make) in
            make.top.equalTo(noteView.snp.bottom).offset(11)
            make.left.right.height.equalTo(noteView)
        }
        
    }
    
    private func getCell(img:UIView, label:UILabel) -> UIView{
        let cellView = UIView()
        view.addSubview(cellView)
        cellView.backgroundColor = UIColor.white
        cellView.addSubview(img)
        cellView.addSubview(label)
        img.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(26)
            make.height.width.equalTo(18)
        }
        label.sizeToFit()
        label.font = UIFont(name: "PingFang SC", size: 15)
        label.textColor = UIColor(hexString:"#496069")
        label.numberOfLines = 0
        label.snp.makeConstraints { (make) in
            make.centerY.equalTo(img)
            make.left.equalTo(img.snp.right).offset(27)
        }
        return cellView
    }

}
